<?php 
class Tag
{

    public $tag = array(
        'goods' => array('block' => 1, 'level' => 4),
        'category' => array('block' => 1, 'level' => 4),
        'brand' => array('block' => 1, 'level' => 4)
    );

    /**
     * 商品
     * @param  [type] $attr    [description]
     * @param  [type] $content [description]
     * @return [type]          [description]
     */
    function _goods($attr, $content)
    {
        //显示商品的条数
        $row = isset($attr['row']) ? intval($attr['row']) : 10;
        $cid = isset($attr['cid']) ? intval($attr['cid']) : null;
        $where = "";

        if ($cid) {
            $where = "'category_cid=" . $cid . "'";
        }

        $php = '<?php ';
        $php .= '$db = M("g_goods");';
        $php .= '$goods = $db->field("gname,price,gid,index_pic")->limit(' . $row . ')->where(' . $where . ')->all();';
        $php .= 'foreach ($goods as $field):?>';
        $php .= $content;
        $php .= '<?php endforeach;?>';

        return $php;
    }

    /**
     * 商品栏目
     * @param  [type] $attr    [description]
     * @param  [type] $content [description]
     * @return [type]          [description]
     */
    function _category($attr, $content)
    {
        $level = isset($attr['level']) ? intval($attr['level']) : null;
        $pid = isset($attr['pid']) ? $attr['pid'] : NULL;
        $cid = isset($attr['cid']) ? $attr['cid'] : NULL;
        $where_level = "";
        $where_level = "'level=" . $level . "'";

        $where_pid = "";
        if ($pid) {
            $where_pid = "'pid='." . $pid;
        }

        $where_cid = "";
        if ($cid) {
            $where_cid = "'category_cid='." . $cid;
        }
        $php = '<?php ';
        $php .= '$db=M("category");';
        $php .= '$category= $db->where(' . $where_level . ')->where(' . $where_pid . ')->where(' . $where_cid . ')->all();';
        $php .= 'foreach($category as $field_'.$level.'):?>';
        $php .= $content;
        $php .= '<?php endforeach;?>';
        return $php;
    }


    /**
     * 商品品牌
     * @param  [type] $attr    [description]
     * @param  [type] $content [description]
     * @return [type]          [description]
     */
    function _brand($attr, $content)
    {

    }


}

 